<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  version="1.0" >

<!-- rule for the whole document: root element is page -->

<xsl:template match="store">
  <base>
<title>Import for ePizza</title>
   <xsl:apply-templates select="products/pizza"/>

        
    <xsl:apply-templates select="products/drink"/>
    
    <xsl:apply-templates select="menus/menu"/>
  

    <xsl:apply-templates select="products/ingredient"/>
</base>
 
</xsl:template>

<!-- A series of XSLT rules that produce fo:blocks to be inserted above -->

  
  <xsl:template match="ingredient">
<xsl:element name="ingredientBase">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="stock"><xsl:value-of select="stock"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="name"/></xsl:attribute>
</xsl:element>
  </xsl:template>

 <xsl:template match="pizza">
<xsl:element name="pizza">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="price"><xsl:value-of select="price"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="name"/></xsl:attribute>
<xsl:attribute name="vegetarian">false</xsl:attribute>
    
    <xsl:for-each select="ingredients">
         <xsl:apply-templates select="."/>
    </xsl:for-each>


</xsl:element>
    
  </xsl:template>
  
  <xsl:template match="drink">
<xsl:element name="boisson">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="name"/></xsl:attribute>
<xsl:attribute name="price"><xsl:value-of select="price"/></xsl:attribute>
</xsl:element>
  </xsl:template>


  <xsl:template match="menu">
<xsl:element name="menu">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
<xsl:attribute name="name"><xsl:value-of select="name"/></xsl:attribute>
<xsl:attribute name="description"><xsl:value-of select="description"/></xsl:attribute>
<xsl:attribute name="price"><xsl:value-of select="price"/></xsl:attribute>
<xsl:attribute name="nbBoissons"><xsl:value-of select="count(products/product)"/></xsl:attribute>
<xsl:attribute name="nbPizzas">-1</xsl:attribute>
</xsl:element>
  </xsl:template>
  

 <xsl:template match="ingredients/ingredient">
<xsl:element name="ingredient"><xsl:value-of select="/store/products/ingredient[@id=current()/@id]/name"/></xsl:element>
</xsl:template>



</xsl:stylesheet>
